const express = require('express');
const graphqlHTTP = require('express-graphql');
const { buildSchema } = require('graphql');
const mainRouter = require('./routes/mainRouter');
const schema = require('./schema/index');
const cors = require('cors')
const app = express();

/* no need for this route anymore */
/* app.use('/api', mainRouter); */

// The root provides a resolver function for each API endpoint
var root = {
  hello: () => {
    return 'Hello world!';
  },
};

app.use(cors());

app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: root,
  graphiql: true,
}));

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(4000);

console.log('Running a GraphQL API server at localhost:4000/graphql');
